<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个税计算器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f8ff; /* 浅蓝色背景 */
            margin: 0;
            padding: 20px;
        }

        #container {
            display: flex;
            justify-content: space-between;
            max-width: 900px;
            margin: auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        #zuo,
        #you {
            width: 45%;
            background-color: #ffe4e1; /* 粉色背景 */
            border-radius: 10px;
            padding: 15px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        input[type="text"] {
            width: calc(100% - 42px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        button {
            padding: 10px;
            margin-top: 10px;
            background-color: #add8e6; /* 浅蓝色按钮 */
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #87ceeb; /* 浅蓝色按钮悬停效果 */
        }

        span {
            color: chocolate;
            font-weight: bold;
        }
    </style>
    <script>
        function shuru() {
            var gongzi = document.getElementById("gongzi").value;
            document.getElementById("leiji").value = gongzi; // 更新累计值
        }

        function jisuan() {
            var gongzi = parseFloat(document.getElementById("gongzi").value) || 0;
            var shebao = parseFloat(document.getElementById("shebao").value) || 0;
            var zhuanxiang = parseFloat(document.getElementById("zhuanxiang").value) || 0;
            var shuiLv = 0; // 个人所得税税率设为0

            if (gongzi > 5000) {
                shuiLv = 0.3; // 个人所得税率
            } 

            var shui = gongzi - shebao - zhuanxiang; // 应纳税所得额

            // 如果工资在5000以下, 应纳税所得额设为0
            if (shui <= 0) {
                document.getElementById("shui").innerText = "0.00";
                document.getElementById("shuiLv").innerText = "0%";
                document.getElementById("leiji2").value = "0.00";
                document.getElementById("realSalary").value = (gongzi - shebao - zhuanxiang).toFixed(2);
                document.getElementById("yingfu").value = "0.00";
                return;
            }

            var jisuan = shui * shuiLv; // 应缴税款
            var leiji = gongzi - jisuan; // 实发工资
            var yingfu = leiji - shebao; // 应补(退)税款

            // 显示结果
            document.getElementById("shui").innerText = shui.toFixed(2);
            document.getElementById("shuiLv").innerText = (shuiLv * 100).toFixed(2) + "%";
            document.getElementById("leiji2").value = jisuan.toFixed(2);
            document.getElementById("realSalary").value = leiji.toFixed(2);
            document.getElementById("yingfu").value = yingfu.toFixed(2);
        }

        function reset() {
            document.getElementById("gongzi").value = "";
            document.getElementById("shebao").value = "";
            document.getElementById("zhuanxiang").value = "";
            document.getElementById("leiji").value = "";
            document.getElementById("shui").innerText = "0.00";
            document.getElementById("shuiLv").innerText = "0%";
            document.getElementById("leiji2").value = "";
            document.getElementById("realSalary").value = "";
            document.getElementById("yingfu").value = "";
        }
    </script>
</head>

<body>
    <div id="container">
        <div id="zuo">
            <h3>个人所得税计算器</h3>
            收入类型：工资、薪资所得（税前）
            <br><br>
            本月工资：<input type="text" id="gongzi" oninput="shuru()" placeholder="请输入本月工资">
            <br>
            累计：<input type="text" id="leiji" readonly>
            <br>
            各项社会保险费：<input type="text" id="shebao" placeholder="请输入社保费用">
            <br>
            专项附加扣：<input type="text" id="zhuanxiang" placeholder="请输入专项附加扣">
            <br>
            <button onclick="jisuan()">计算</button>
        </div>

        <div id="you">
            <h3>个人所得税计算结果</h3>
            应纳税所得额：<span id="shui" style="color: chocolate;">0.00</span> 元
            <br>
            应用税率：<span id="shuiLv" style="color: chocolate;">0%</span>
            <br>
            速算扣除数：<input type="text" id="leiji2" readonly>元
            <br>
            实发工资：<input type="text" id="realSalary" readonly>元
            <br>
            应补(退)税款：<input type="text" id="yingfu" readonly>元
            <br>
            <button onclick="reset()">重置</button>
        </div>
    </div>
</body>

</html>
